const cluster = require('cluster');

const cpuLens = require('os').cpus().length;

const http = require('http');

if(cluster.isMaster){ //判断是否是主进程
    for(let i = 0;i<cpuLens;i++){
        cluster.fork();
        
    } 
}else{
    http.createServer((req,res) => {
        res.end('ok')
    }).listen(3000)
}

cluster.on('exit',(worker) => {
    console.log(`工作进程 ${worker.process.pid} 已退出`);
    cluster.fork()
})